﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Title="Change Password" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="content" ContentPlaceHolderID="MainContent" runat="server">

	<h2>Change Password</h2>

	<% if( ( TempData["ErrorMessage"] ?? ViewData["ErrorMessage"] ) != null ){ %>
	<p class="MvcMembershipError"><% =(string)TempData["ErrorMessage"] ?? (string)ViewData["ErrorMessage"]%></p>
	<% } %>
	
	<% if (ViewData["Success"] != null && (bool)ViewData["Success"] == true) { %>
	<h3>Your password has been changed!</h3>
	<% } %>

	<% using (Html.Form("FormsAuthentication", "ChangePassword"))
    { %>
	<fieldset class="MvcMembership">
		<legend>Change Password</legend>
		<div><label for="currentPassword">Current Password:</label> <% =Html.Password("currentPassword")%></div>
		<div><label for="newPassword">New Password:</label> <% =Html.Password("newPassword")%></div>
		<div><label for="newPasswordConfirm">Confirm New Password:</label> <% =Html.Password("newPasswordConfirm")%></div>
		<div><% =Html.SubmitButton( "submit", "Change Password", new { onclick = "return starterKit_mvc_membership_validateChangePassword();" } )%></div>
	</fieldset>
	<% } %>

	<script type="text/javascript">
	/* <![CDATA[ */

		function starterKit_mvc_membership_validateChangePassword()
		{

			var pwd_minChars = <% =(int)ViewData["MinimumPasswordLength"] %>;
			var pwd_minNonAlphaChars = <% =(int)ViewData["MinimumNonAlphaNumericCharacters"] %>;

			var currentPassword = document.getElementById('currentPassword').value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
			if( currentPassword.length < 1 )
			{
				alert( 'Please enter your current password.' );
				document.getElementById('currentPassword').focus();
				return false;
			}

			var newPassword = document.getElementById('newPassword').value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
			if( newPassword.length < 1 )
			{
				alert( 'Please enter your new password.' );
				document.getElementById('newPassword').focus();
				return false;
			}
			if( newPassword.length < pwd_minChars )
			{
				alert( 'Your new password must be at least ' + pwd_minChars + ' characters long.' );
				document.getElementById('newPassword').focus();
				return false;
			}
			var nonAlphaChars = newPassword.replace( /[a-zA-Z0-9]*/, '' );
			if( nonAlphaChars.length < pwd_minNonAlphaChars )
			{
				alert( 'Your new password must contain at least ' + pwd_minNonAlphaChars + ' non alphanumeric characters.' );
				document.getElementById('newPassword').focus();
				return false;
			}

			var newPasswordConfirm = document.getElementById('newPasswordConfirm').value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
			if( newPasswordConfirm.length < 1 )
			{
				alert( 'Please confirm your new password.' );
				document.getElementById('newPasswordConfirm').focus();
				return false;
			}
			if( newPassword != newPasswordConfirm )
			{
				alert( 'Please make sure what you entered in to the "Confirm New Password" textbox matches the new password you are trying to create.' );
				document.getElementById('newPassword').focus();
				return false;
			}

			return true;

		}

	/* ]]> */
	</script>

</asp:Content>
